package com.zxc.common.exception;

import com.zxc.common.enums.ShoppingEnum;
import com.zxc.common.vo.ExceptionVo;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

//标识当前是一个处理一次的控制器类
@ControllerAdvice
public class ShoppingExceptionHandler{

    @ExceptionHandler(ShoppingException.class)
    public ResponseEntity<ExceptionVo> handleException(ShoppingException ex){
        System.out.println("进入异常处理类......");
        //从异常中的到枚举
        ShoppingEnum shoppingEnum = ex.getShoppingEnum();
        return ResponseEntity.status(shoppingEnum.getCode()).body(new ExceptionVo(shoppingEnum));
    }

}
